package com.hdjk.view.callback;

import com.hdjk.view.entity.PerformanceEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetFundPerformanceCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONObject obj = (JSONObject) msg.getData();
        if (obj !=null) {
            List<PerformanceEntity> list = new ArrayList<>();
            if (!obj.isNull("typeAverage")) {
                PerformanceEntity entity = new PerformanceEntity();
                JSONObject object = obj.getJSONObject("typeAverage");
                if (!object.isNull("day1")) {
                    double l = object.getDouble("day1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setDay1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("month1")) {
                    double l = object.getDouble("month1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMonth1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("month3")) {
                    double l = object.getDouble("month3");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMonth3(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("month6")) {
                    double l = object.getDouble("month6");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMonth6(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("sinceLaunch")) {
                    double l = object.getDouble("sinceLaunch");
                    BigDecimal b = new BigDecimal(l);
                    entity.setSinceLaunch(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("week1")) {
                    double l = object.getDouble("week1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setWeek1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("year1")) {
                    double l = object.getDouble("year1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYear1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("year2")) {
                    double l = object.getDouble("year2");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYear2(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("year3")) {
                    double l = object.getDouble("year3");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYear3(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("yearToDate")) {
                    double l = object.getDouble("yearToDate");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYearToDate(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                list.add(entity);
            }
            if (!obj.isNull("stageReturn")) {
                PerformanceEntity entity = new PerformanceEntity();
                JSONObject object = obj.getJSONObject("stageReturn");
                if (!object.isNull("day1")) {
                    double l = object.getDouble("day1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setDay1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("month1")) {
                    double l = object.getDouble("month1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMonth1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("month3")) {
                    double l = object.getDouble("month3");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMonth3(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("month6")) {
                    double l = object.getDouble("month6");
                    BigDecimal b = new BigDecimal(l);
                    entity.setMonth6(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("sinceLaunch")) {
                    double l = object.getDouble("sinceLaunch");
                    BigDecimal b = new BigDecimal(l);
                    entity.setSinceLaunch(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("week1")) {
                    double l = object.getDouble("week1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setWeek1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("year1")) {
                    double l = object.getDouble("year1");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYear1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("year2")) {
                    double l = object.getDouble("year2");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYear2(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("year3")) {
                    double l = object.getDouble("year3");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYear3(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                if (!object.isNull("yearToDate")) {
                    double l = object.getDouble("yearToDate");
                    BigDecimal b = new BigDecimal(l);
                    entity.setYearToDate(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                }
                list.add(entity);
            }
            msg.setData(list);
        }
        return msg;
    }
}
